package a66weding.com.jiehuntong.common.utils;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import a66weding.com.jiehuntong.R;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/8/28
 * @description :
 */
public class PopUtils  {

    public static PopupWindow showCommitPop(Context context, View view){


            // 一个自定义的布局，作为显示的内容
            View contentView = LayoutInflater.from(context).inflate(
                    R.layout.pop_wrapscreen_commit, null);

         final PopupWindow   mCommitpop = new PopupWindow(contentView,
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);

            //点击空白处时，隐藏掉pop窗口
            mCommitpop.setTouchable(true);

            mCommitpop.setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(R.color.whitetranslucenthalf2)));


            contentView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCommitpop.dismiss();
                }
            });


            mCommitpop.setTouchInterceptor(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    mCommitpop.dismiss();
                    return true;
                    // 这里如果返回true的话，touch事件将被拦截
                    // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
                }
            });

            //设置位置
            mCommitpop.showAtLocation(view, Gravity.CENTER|Gravity.CENTER_HORIZONTAL,0,0);//设置在屏幕中的显示位置

            // 设置好参数之后再show
            mCommitpop.showAsDropDown(view);


            return mCommitpop;

    }


}
